package com.tanxi521.springboot.controller;

import com.tanxi521.springboot.pojo.APIResult;
import com.tanxi521.springboot.pojo.Player;
import com.tanxi521.springboot.pojo.RegHeader;
import com.tanxi521.springboot.service.PlayerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@CrossOrigin
@RequestMapping("/player")
@Api(tags = "玩家操作接口")
public class PlayerController {

    @Autowired
    private PlayerService playerService;

    @PostMapping("/reg")
    @ApiOperation(value = "注册器接口", notes = "仅限注册器登录")
    @RegHeader
    public APIResult reg(@RequestBody Player player) {
        int count = playerService.regNewPlayer(player);
        return count != 0 ? new APIResult(APIResult.SUCCESS, "注册成功, 可以登录游戏了哦") :
                new APIResult(APIResult.FAIL, "注册失败，请重试/请勿重复注册");
    }
}
